package com.zhouke.certificate.controller;

import com.zhouke.certificate.chat.ChatService;
import com.zhouke.certificate.support.CustomConnectionKeepAliveStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

import java.time.Duration;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/chat")
public class ChatController {
    //使用微服务实现

//    @Autowired
//    private RestTemplate restTemplate;
    @Autowired
    private ChatService chatService;

    @GetMapping
    public String chat(@RequestParam(defaultValue = "")String message){
//        //请求
//        UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://chatgpt-server/chat")
//                .queryParam("message", message);
//        RequestEntity<Void> request=new RequestEntity<>(HttpMethod.GET, builder.build().toUri());
//
//        //返回
//        ResponseEntity<String > response=restTemplate.exchange(request,String.class);
//        String ret= response.getBody();
        String ret=chatService.chat(message);
        return "{\"message\":\""+ret+"\"}";

    }


}
